src = "/data1/zyx/yks/sources/Detectron/output_retail_stage2/rcnn/results_1539151523.98_rcnn.txt"

import pandas as pd
import os
result = pd.read_csv(src,sep='\t',header=None,names=["filename","minx","miny","maxx","maxy","confindence","classid"])
result["filename"] = result["filename"].apply(lambda x: os.path.basename(x))

idmap = "/data1/zyx/yks/dataset/retail/map_test2.csv"
id2name = open(idmap,"rt").readlines()[1:]
id2name = {l.strip().split(',')[0]:l.strip().split(',')[1] for l in id2name}

result["image_id"] = result["filename"].apply(lambda x: id2name[x])
result["flg"] = 2
# result = result[result["score"] > 0.75]

result.to_csv("output/restail_stage2/{}".format(os.path.basename(src)),index=False)